package com.szss.springbootfirst.controller;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author wcx
 * @date 2023/2/4 8:48
 */

@RestController
public class RedisController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/redis")
    public String redisAddData(){
        ValueOperations ops = stringRedisTemplate.opsForValue();
        ops.set("name","zhangshan");
        return "add success!";
    }

    @RequestMapping("/getRedisData")
    public String getRedisData(){
        ValueOperations ops = stringRedisTemplate.opsForValue();
        return (String) ops.get("name");
    }
}
